package com.ruoyi.adopt.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.adopt.mapper.PetMapper;
import com.ruoyi.adopt.domain.Pet;
import com.ruoyi.adopt.service.IPetService;

import javax.annotation.Resource;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
import static com.ruoyi.common.utils.SecurityUtils.getUserId;

/**
 * 领养/送养Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-22
 */
@Service
public class PetServiceImpl implements IPetService
{
    @Resource
    private PetMapper petMapper;

    /**
     * 查询宠物
     *
     * @param petId 宠物主键
     * @return 宠物
     */
    @Override
    public Pet selectPetByPetId(Long petId)
    {
        return petMapper.selectPetByPetId(petId);
    }

    /**
     * 查询宠物列表
     *
     * @param pet 宠物
     * @return 宠物
     */
    @Override
    public List<Pet> selectPetList(Pet pet)
    {
        return petMapper.selectPetList(pet);
    }

    /**
     * 新增宠物
     *
     * @param pet 宠物
     * @return 结果
     */
    @Override
    public int insertPet(Pet pet)
    {
        pet.setCreateUserId(getUserId());
        pet.setCreateUserName(getLoginUser().getUser().getNickName());
        pet.setCreateTime(DateUtils.getNowDate());
        pet.setUpdateTime(DateUtils.getNowDate());
        pet.setIsDelete("0");
        pet.setIsAdopted("0");
        return petMapper.insertPet(pet);
    }

    /**
     * 修改宠物
     *
     * @param pet 宠物
     * @return 结果
     */
    @Override
    public int updatePet(Pet pet)
    {
        pet.setUpdateTime(DateUtils.getNowDate());
        return petMapper.updatePet(pet);
    }

    /**
     * 批量删除宠物
     *
     * @param petIds 需要删除的宠物主键
     * @return 结果
     */
    @Override
    public int deletePetByPetIds(Long[] petIds)
    {
        return petMapper.deletePetByPetIds(petIds);
    }

    /**
     * 删除宠物信息
     *
     * @param petId 宠物主键
     * @return 结果
     */
    @Override
    public int deletePetByPetId(Long petId)
    {
        return petMapper.deletePetByPetId(petId);
    }
}
